const mysql = require('mysql');
const fs = require('fs');
let readline = require('readline');
const connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'features'
})
connection.connect(err=> {
    if(err) throw err;
    console.log('数据库连接成功!');
})

function readFileToArr(fReadName,callback) {
    let fRead = fs.createReadStream(fReadName);
    let objReadline = readline.createInterface({
        input:fRead
    })

    objReadline.on('line',line => {
        let lineArr= line.trim().split("\t")
        let chromosomeName = lineArr[0]
        let geneName = lineArr[1]
        let type = lineArr[2]
        let alternativeSplicingType = lineArr[3]
        let alternativeSplicingFeatures = lineArr[4]
        let addSql = 'insert into t_item(chromosomeName,geneName,type,alternativeSplicingType,alternativeSplicingFeatures) values(?,?,?,?,?)'
        let addSqlParams = [chromosomeName,geneName,type,alternativeSplicingType,alternativeSplicingFeatures]

        connection.query(addSql,addSqlParams,function(err,result){
            if(err){
                console.log(err.message)
                return;
            }
            console.log("----------------------------------------------------")
            console.log('INSERT ID:',result);        
            console.log('------------------------------------------------\n\n');  
        })
    })
}


readFileToArr('可变剪接特征.txt',"utf-8")




